package main;

import org.newdawn.slick.*;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.state.transition.*;

public class MainMenuState extends BasicGameState {

	public static final int ID = 2;
	Image splash;
	Color color;
	Image startButton;
	Image optionButton;
	Image exitButton;

	@Override
	public void init(GameContainer gc, StateBasedGame sbg)
			throws SlickException {
		// TODO Auto-generated method stub
	}
	
	@Override
	public void enter(GameContainer gc, StateBasedGame sbg) throws SlickException {
		splash = new Image("/res/splashArt.png");
		startButton = new Image("/res/startButton2.png");
		optionButton = new Image("/res/optionsButton2.png");
		exitButton = new Image("/res/exitButton2.png");
	}

	@Override
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
			throws SlickException {
		// TODO Auto-generated method stub
		g.setColor(Color.white);
		g.fillRect(0, 0, gc.getWidth(), gc.getHeight());
		g.drawImage(splash, 0, 0);
		// draw start button
		Rectangle buttonRectStart = getStartGameButtonRect(gc);
		g.drawImage(startButton, buttonRectStart.getX(), buttonRectStart.getY());
		// draw option button
		Rectangle buttonRectOptions = getOptionsButtonRect(gc);
		g.drawImage(optionButton, buttonRectOptions.getX(), buttonRectOptions.getY());
		// draw exit button
		Rectangle buttonRectExit = getExitButtonRect(gc);
		g.drawImage(exitButton, buttonRectExit.getX(), buttonRectExit.getY());
	}

	@Override
	public void update(GameContainer gc, StateBasedGame sbg, int delta)
			throws SlickException {
		// TODO Auto-generated method stub
		Input input = gc.getInput();
		if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
			Rectangle buttonRectStart = getStartGameButtonRect(gc);
			Rectangle buttonRectOptions = getOptionsButtonRect(gc);
			Rectangle buttonRectExit = getExitButtonRect(gc);
			if (buttonRectStart.contains(input.getMouseX(), input.getMouseY())) {
				sbg.enterState(GameState.ID, new FadeOutTransition(), new FadeInTransition());
			}
			if (buttonRectOptions.contains(input.getMouseX(), input.getMouseY())) {
				sbg.enterState(OptionsState.ID, new FadeOutTransition(), new FadeInTransition());
			}
			if (buttonRectExit.contains(input.getMouseX(), input.getMouseY())) {
				gc.exit();
			}
		}
	}

	private Rectangle getStartGameButtonRect(GameContainer gc) {
		// TODO Auto-generated method stub
		int boxWidth = 194;
		int boxHeight = 59;
		return new Rectangle(gc.getWidth() / 2 - boxWidth / 2 - 200, gc.getHeight() - boxHeight - 80, boxWidth, boxHeight);
	}
	
	private Rectangle getOptionsButtonRect(GameContainer gc) {
		// TODO Auto-generated method stub
		int boxWidth = 194;
		int boxHeight = 59;
		return new Rectangle(gc.getWidth() / 2 - boxWidth / 2 , gc.getHeight() - boxHeight - 80, boxWidth, boxHeight);
	}
	
	private Rectangle getExitButtonRect(GameContainer gc) {
		// TODO Auto-generated method stub
		int boxWidth = 194;
		int boxHeight = 59;
		return new Rectangle(gc.getWidth() / 2 - boxWidth / 2 + 200, gc.getHeight() - boxHeight - 80, boxWidth, boxHeight);
	}

	@Override
	public int getID() {
		// TODO Auto-generated method stub
		return ID;
	}

}
